home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 028a / uuduue.zip / UUDECODE.DOC next >
Text File  |  1991-10-19  |  12KB  |  261 lines

  1.  
  2. UU-encoding is a way to code a file which may contain any characters into
  3. a standard character set that can be reliably sent over diverse networks.
  4.  
  5.  
  6. THE CHARACTER ENCODING:
  7.  
  8. The basic scheme is to break groups of 3 eight bit characters (24 bits) into
  9. 4 six bit characters and then add 32 (a space) to each six bit character
  10. which maps it into the readily transmittable character.  Another way of
  11. phrasing this is to say that the encoded 6 bit characters are mapped into
  12. the set:
  13.         `!"#$%&'()*+,-./012356789:;<=>?@ABC...XYZ[\]^_
  14. for transmission over communications lines.
  15.  
  16. As some transmission mechanisms compress or remove spaces, spaces are changed
  17. into back-quote characters (a 96).  (A better scheme might be to use a bias
  18. of 33 so the space is not created, but this is not done.)
  19.  
  20. Another newer less popular encoding method, called XX-encoding uses the set:
  21.         +-01..89ABC...XYZabc...xyz
  22.  
  23. In my opinion, XX-encoding is superior to UU-encoding because it uses more
  24. "normal" characters that are less likely to get corrupted.  In fact several
  25. of the special characters in the UU set do not get thru an EBCDIC to ASCII
  26. translation correctly.  Conversely, an advantage of the UU set is that it does
  27. not use lower case characters.  Now-a-days both upper and lower case are sent
  28. with no problems; maybe in the communications dark ages, there was a problem
  29. with lower case.
  30.  
  31. This "UU" encode/decode pair can handle either XX or UU encoding.  The encode
  32. program defaults to creating a UU encoded file; but can be run with a "-x"
  33. option to create an XX encoding.
  34.  
  35. The decode program defaults to autodetect.  However the program can get
  36. confused by comment lines preceeding the actual encoded data.  The decode
  37. mode can be forced to UU or XX with the "-u" or "-x" parameter.
  38.  
  39. Another option is for the actual map table to be inserted at the front of the
  40. file.  The format for this is discussed later.  The table parameters are
  41. detected and used by this decode program.  (A table will override the "-x" or
  42. "-u" parameters.)  The encode program can be run with a "-t" option which
  43. tells it to put the table into the encoded file.
  44.  
  45. A third encode mapping is the one used by Brad Templeton's ABE program.  This
  46. is not handled by these programs as the check and control information
  47. surrounding the actual encoded data is in a different form.
  48.  
  49. From a theoritical view, this encoding is breaking down 24 bits modulo 64.  Note
  50. that 64**3 is = 2**24.  The result is 24 bits in for 32 bits out, a 33% size
  51. increase.  Note that 85**5 > 2**32.  Also note that there are 94 transmittable
  52. ASCII characters (from 0x21 thru 0x7e).  Thus modulo 85 encoding (the atob
  53. encoder) transforms 32 bits to 5 ASCII chars or 40 bits for a 25% size increase.
  54.  
  55. The trade off in the module 85 encoding is that many communications systems do
  56. not reliably transmit 85 ASCII characters.  The tidla, carrot, brackets, and
  57. sometimes upper or lower case frequently get corrupted.
  58.  
  59. COMPOSING A LINE OF ENCODED CHARACTERS:
  60.  
  61. A small number of eight bit characters are encoded into a single line and a
  62. count is put at the start of the line.  (Most lines in an encoded file have 45
  63. encoded characters.  When you look at a UU-encoded file note that most lines
  64. start with the letter "M".  "M" is decimal 77 which, minus the 32 bias, is 45.)
  65.  
  66. This encode program puts a check character at the end of each line.  The check
  67. is the sum of all the encoded characters, before adding the mapping, modulo 64.
  68.  
  69. Note: Horton 9/1/87 UUENCODE has a bug in the line check algorithm; it uses the
  70. sum of the original, not the encoded characters.  This decode program accepts
  71. either form of line check character.
  72.  
  73. In previous versions (4.13 and lower) the line check characters was generated by
  74. default by this encode program and was supressed with the "-L" option.  One
  75. reason to supress them is if they will be decoded by one of the old Horton
  76. decoders.  Most decoders either accept this form of check or simply stop looking
  77. after the line length is exhausted.  My feelings are mixed about the line
  78. checksums because errors of this type essentially never occur.
  79.  
  80. However with modern, error-free communications systems and with the CRC checks
  81. on the entire file (see below) I have made the default for uuencoding to have NO
  82. line level check characters effective version 4.21.  The "-L" option on uuencode
  83. turns on generation of line checksums.  If you have a really bad communications
  84. system and you want to isolate a problem, turn them on.
  85.  
  86. Uudecode automatically checks for the presense line checksums, so the default
  87. for uudecode is to leave line level checks on; if there are some problems the
  88. "-L" option for uudecode turns them off.  Sometimes there is junk at the end of
  89. the line which causes spurious line checksum errors.
  90.  
  91. I have encountered various other ways that encoders end lines.  One encoder
  92. put a "M" at both the start and end of the line.  Another used a line count
  93. character.  This decode program checks all of these.  I would not be surprised
  94. if some encoder out there ends lines with astrological symbols.  If you
  95. encounter some other wierd form of encoded file, let me know.
  96.  
  97.  
  98. PACKAGING THE LINES INTO FILES:
  99.  
  100. The lines of encoded data can be preceded by comments and by network addressing
  101. information.  The encoded data is directly preceded by a line containing:
  102.  
  103.              begin <file-mode> <file-name>
  104.  
  105. This line is created by the encoding program.  The decode program scans the
  106. file looking for "begin" in column 1.
  107.  
  108. The final end of encoded data is an encoded line with zero encoded characters
  109. (a back-quote), followed by a line containing "end".
  110.  
  111. For integrity checking, various encode programs insert checksums for the
  112. entire file.  This decode tries to check for all known types of file checksums.
  113. This is discussed in more detail later.
  114.  
  115. This encode program puts a header line, containing the section number and
  116. file name, in front of every section:
  117.  
  118.          "section <number> of uuencode of file <file name>"
  119.  
  120. At the end of a section the encode program inserts a line containing checksum
  121. and file size information.  This can be suppressed with the "-c" option.
  122.  
  123. All the "integrity fields" (the checksum, the line check, and the section
  124. header line) are inserted in a way that they will be ignored by other UUDECODE
  125. programs that cannot handle them.  This decode program does not require any of
  126. these fields; if not present, integrity checking is not done.  This program
  127. pair is 100% downward compatible!
  128.  
  129.  
  130. SPLITING UP LONG FILES:
  131.  
  132. Long files are broken into several sections before transmission.  This is
  133. done because very large files are cumbersome to handle and because some
  134. networks require files to be less than 64K bytes.
  135.  
  136. This encode program automatically breaks large encoded files into sections.
  137. This split is controlled by several options.  First the "-s" option tells
  138. encode not to split the file.  The "-s nnn" option tells encode to split the
  139. file into hunks of "nnn" lines.  The default is 950 lines which is about 59k.
  140. Sometimes extensive comments are put into the first file; thus it may be
  141. necessary for the first file to contain fewer encoded lines.  The "-h nnn"
  142. option tells encode to leave room for "nnn" additional lines in the first file.
  143.  
  144. If the data file being encoded is called FOO.ZIP, then the encode program
  145. names the encoded files FOO1.UUE, FOO2.UUE, etc.
  146.  
  147. The decode program searches for the various sections, scans over preliminary
  148. comments and decodes all as if they were one big file.  Decode is passed the
  149. base file name "FOO".
  150.  
  151. Decode can (but rarely does) get confused and thinks header lines are encoded
  152. data.  If so, edit the file and try again.  This has only happened once to me
  153. and I have decoded a lot of files.
  154.  
  155. When decode encounters a premature end-of-file or some data which is not
  156. decodable, it assumes the end of a file section.  decode is conservative when
  157. it encounters data it cannot decode.
  158.  
  159. Usually this undecodable data is valid "trailer" data put at the end of file
  160. for data transmission purposes.  However the file may be bad.  So decode
  161. continues to scan the file, if decode then encounters a line which is decodable
  162. it assumes the file is bad.  Or if there are more than 30 lines remaining in
  163. the file, decode assumes the file is bad.
  164.  
  165. When decode encounters a valid end of file section it must get the next file
  166. in sequence.  If the file name ends with a number, decode tries the next file
  167. name in numeric sequence.  Otherwise decode asks for a file name.  If this
  168. file does not contain decodable data, decode asks for another file to try.
  169.  
  170. The "SECTION" line inserted by the encode program is used for validity checking
  171. only.  If not present, decode will accept any file containing encoded lines.
  172.  
  173.  
  174. OTHER FILE FORMS:
  175.  
  176. Sometimes files come across in shell archives that automatically check
  177. sequencing and call uudecode for you on the UNIX systems.  If you prefer to
  178. download the raw files to MS-DOS, this decode program will filter thru simple
  179. shell scripts and decode the data automatically.
  180.  
  181. There is one more rarely used feature of ENCODE: many input files can be
  182. encoded into one large encode file.  (I have never seen this used.)  The end
  183. of an input file is a zero length encoded line, followed by another "begin"
  184. line instead of by an "end" line.  This decode program will decode this sort of
  185. file; but the encode will only handle a single input file.
  186.  
  187.  
  188. FILE LEVEL CHECKSUMS:
  189.  
  190. There are three types of file checksums found in encoded files:
  191.  
  192.        UUENCODE 2.14 and below inserted lines that gave the section
  193.        size and the original input file size.  This is supplanted
  194.        by a better technique in 3.07; but 3.07 UUDECODE still checks
  195.        and validates the old form
  196.  
  197.        UUENCODE 3.07 and Rahul Dhesi''s encode scripts compute a Unix
  198.        "sum -r" on the encoded sections and on the original input file.
  199.        A difference is that UUENCODE 3.07 puts the expected "sum -r"
  200.        and size at the end of a file while Rahul''s scripts put them at
  201.        begining.  This UUDECODE analyzes either.
  202.  
  203.        The third form of checksum is a full 32 bit CRC that Rahul''s script
  204.        inserts.  My code does not handle this.  Rahul has written the
  205.        BRIK program to check them.  If there is a "sum -r" failure, BRIK
  206.        analysis should be considered.
  207.  
  208. Also Unisys Unix platforms put a line containing just the original file size at
  209. the end of the encoded file.  My code checks this.
  210.  
  211.  
  212. TABLE LINES:
  213.  
  214. Some encoded files but the mapping used at the front of the encoded file,
  215. just in front of the "begin" line.  The format for this is:
  216.  
  217.                    table
  218.                    first 32 characters
  219.                    second 32 characters
  220.  
  221. All this starts in column 1.
  222.  
  223. If decode encounters a table specification, it uses it and overrides any
  224. command line parameters.  Encode will create the table lines if run with
  225. the "-t" parameter.
  226.  
  227.  
  228. COMPLETION CODES:
  229.  
  230. On successful completion, UUDECODE sets ERRORLEVEL to 0.  If there are any
  231. problems, ERRORLEVEL is set to non-zero.
  232.  
  233. Most of the options to UUDECODE are obvious.  However, the "-e" option needs
  234. more explanation.  The purpose of "-e" is to automatically run an un-archiver
  235. (like ZOO or PKUNPAK) when UUDECODE successfully completes.  If the "-e"
  236. option is given, UUDECODE calls BAT file UNARCUUE on successful completion
  237. UNARCUUE is passed two parameters:
  238.  
  239.                 the filename decoded (with no extension)
  240.                 the file extension.
  241.  
  242. Normally the file extension tells which un-archiver to call.  The UNARCUUE
  243. BAT file, can test these parameters and call the necessary un-archiver.
  244.  
  245.  
  246. This works well for me.  On UNIX I find a program I want in three sections:
  247.               PRG1, PRG2, PRG3.
  248. I copy the three files down to my PC as PRG1.UUE, PRG2.UUE, and PRG3.UUE.  I
  249. then just enter UUDECODE PRG and the thing decodes.
  250.  
  251.  
  252. Done privately and not for profit (freeware).  Suggestions appreciated.
  253. The programs are written in Turbo Pascal 5.5 with about 5% TASM for speed.
  254. The source is not public domain.  I would entertain consulting contracts
  255. for porting to other hardware platforms.
  256.  
  257.  
  258. Richard Marks
  259. 931 Sulgrave Lane
  260. Bryn Mawr, PA 19010
  261.